package cn.com.shopec.erp.system.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

/**
 * 
 * @ClassName Menu
 * @Description 菜单表实体
 * @author chengui
 * @date 2013-5-29 下午5:03:13
 */
@Entity
@Table(name = "tbl_scm_menu")
public class Menu implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6286368869243876683L;
	
	/** 主键. */
	private String id;
	/** 菜单名称. */
	private String menuName;
	/** 菜单URL. */
	private String menuUrl;
	/** 菜单结构. */
	private String structure;
	/** 菜单级别. */
	private int level;
	/** 是否有子菜单:0-没有，1-有. */
	private int hasleaf;
	/** 菜单排序. */
	private int menuSort;
	/** 菜单类型:1-平台，2-供应商. */
	private int menuType;
	/** 备注. */
	private String remark;
	/** 删除标识:0-已删除，1-未删除. */
	private int deleteFlag = 1;
	
	/** 权限. */
	private Access access;
	/** 菜单. */
	private Menu menu;
	
	/** 菜单. */
	private Set<Menu> menus = new HashSet<Menu>();

	public Menu() {
		super();
	}
	public Menu(String id) {
		super();
		this.id = id;
	}
	public Menu(String id, String menuName, String menuUrl, String structure,
			int level, int hasleaf, int menuSort, int menuType, String remark,
			int deleteFlag, Access access, Menu menu, Set<Menu> menus) {
		super();
		this.id = id;
		this.menuName = menuName;
		this.menuUrl = menuUrl;
		this.structure = structure;
		this.level = level;
		this.hasleaf = hasleaf;
		this.menuSort = menuSort;
		this.menuType = menuType;
		this.remark = remark;
		this.deleteFlag = deleteFlag;
		this.access = access;
		this.menu = menu;
		this.menus = menus;
	}
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", unique = true, nullable = false, length = 32)
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	@Column(name = "menu_name")
	public String getMenuName() {
		return menuName;
	}
	public void setMenuName(String menuName) {
		this.menuName = menuName;
	}
	@Column(name = "menu_url")
	public String getMenuUrl() {
		return menuUrl;
	}
	public void setMenuUrl(String menuUrl) {
		this.menuUrl = menuUrl;
	}
	@Column(name = "structure")
	public String getStructure() {
		return structure;
	}
	public void setStructure(String structure) {
		this.structure = structure;
	}
	@Column(name = "menu_level")
	public int getLevel() {
		return level;
	}
	public void setLevel(int level) {
		this.level = level;
	}
	@Column(name = "has_leaf")
	public int getHasleaf() {
		return hasleaf;
	}
	public void setHasleaf(int hasleaf) {
		this.hasleaf = hasleaf;
	}
	@Column(name = "menu_sort")
	public int getMenuSort() {
		return menuSort;
	}
	public void setMenuSort(int menuSort) {
		this.menuSort = menuSort;
	}
	@Column(name = "menu_type")
	public int getMenuType() {
		return menuType;
	}
	public void setMenuType(int menuType) {
		this.menuType = menuType;
	}
	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	@Column(name = "delete_flag")
	public int getDeleteFlag() {
		return deleteFlag;
	}
	public void setDeleteFlag(int deleteFlag) {
		this.deleteFlag = deleteFlag;
	}
	
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "menu_access")
	public Access getAccess() {
		return access;
	}
	public void setAccess(Access access) {
		this.access = access;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "parent_id", referencedColumnName = "id")
	public Menu getMenu() {
		return menu;
	}
	public void setMenu(Menu menu) {
		this.menu = menu;
	}
	
	@OneToMany(mappedBy = "menu", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	public Set<Menu> getMenus() {
		return menus;
	}
	public void setMenus(Set<Menu> menus) {
		this.menus = menus;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Menu other = (Menu) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

}
